package cn.dapeng.base;

import cn.dapeng.util.SleepingUtil;

import java.util.concurrent.TimeUnit;

/**
 * interrupt方法是不能中断锁竞争的
 */

public class SynchronizedAndInterrupt {

    public static void main(String[] args) {
        Object monitor = new Object();

        Thread t1 = new Thread(() -> {
            synchronized (monitor) {
                SleepingUtil.sleep(5, TimeUnit.SECONDS);
            }
        });
        t1.start();

        SleepingUtil.sleep(1, TimeUnit.SECONDS);

        Thread t2 = new Thread(() -> {
            synchronized (monitor) {

            }
            System.out.println("t2 end");
        });

        t2.start();
        SleepingUtil.sleep(1, TimeUnit.SECONDS);
        t2.interrupt();

    }

}
